package cn.hdu.liang.ch5;

import cn.hdu.liang.ch4.Dish;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static cn.hdu.liang.ch4.Dish.menu;

public class DataFilter {
    public static void main(String[] args) {

        //distinct()去除重复
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7);
        numbers.stream().filter(i -> i % 2 == 0)
                .distinct()
                .forEach(System.out::println);

        //截断流
        List<Dish> dishes = menu.stream()
                .filter(d -> d.getCalories() > 300)
                .limit(3)
                .collect(Collectors.toList());
        System.out.println(dishes);

        //跳过元素
        menu.stream().filter(d -> d.getCalories() > 300)
                .skip(2)
                .forEach(s -> System.out.print(s + " "));

    }
}
